home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / jf90.lha / reboot.ascii < prev   
Encoding:
Text File  |  1990-04-02  |  4.1 KB  |  96 lines

  1.  
  2. Sometimes applications need to be able to reboot the Amiga under software 
  3. control.  However, rebooting the machine is very tricky, and most attempts 
  4. have been flawed.  The RESET instruction, for example, unconfigures all 
  5. memory; after RESET there is no reliable place to run user code.  Most 
  6. reboot code will break whenever the memory or CPU configuration is changed.  
  7. Other reset code will not work properly on the Amiga 1000.  
  8.  
  9. In fact, rebooting the Amiga is so tricky that even the official reboot code 
  10. published by Commodore will not work in every case. (This article replaces 
  11. "The Official Way to Software Reboot an Amiga" from the July/August 1989 
  12. issue of Amiga Mail, Exec, page III-9.)  Some versions of the A2000 have 
  13. a 0.1 uf capacitor (C909) on the hardware reset line.  This capacitor has 
  14. the effect of rejecting short reset pulses, including some of those 
  15. generated by the CPU RESET instruction.
  16.  
  17. The ColdReboot() function listed below should be used whenever an application 
  18. needs to reboot the Amiga.  ColdReboot() is the only officially supported way 
  19. to reboot an Amiga under software control. 
  20.  
  21. Even this code will fail under some circumstances.  Some processor cards 
  22. from third-party manufacturers lock up when the RESET instruction is used.   
  23. (Great Valley Products (GVP) offers an upgrade PAL to fix this problem.)  
  24. Likewise, if the user has a 68020 or 68030 coprocessor card and has copied 
  25. the Kickstart ROM image into 32-bit memory with the command SetCPU FASTROM, 
  26. the NewReboot() function will not work properly.  To fix this, give the 
  27. command SetCPU NOFASTROM.
  28.  
  29. TECHNICAL DESCRIPTION: The code below precalculates a jump address, executes 
  30. a RESET instruction, then relies on CPU prefetch to execute the jump.  The 
  31. precalculated jump is constructed to enter the system ROM at the location of 
  32. a second RESET instruction.
  33.  
  34. ****************************************************************************
  35. *
  36. *   NAME
  37. *    ColdReboot - Official code to reset any Amiga (Version 2)
  38. *
  39. *   SYNOPSIS
  40. *    ColdReboot()
  41. *
  42. *    void ColdReboot(void);
  43. *
  44. *   FUNCTION
  45. *    Reboot the machine.  All external memory and peripherals will be
  46. *    RESET, and the machine will start its power up diagnostics.
  47. *
  48. *   NOTE
  49. *    Rebooting an Amiga in software is very tricky.    Differing memory
  50. *    configurations and processor cards require careful treatment.  This
  51. *    code represents the best available general purpose reset.  The 
  52. *    MagicResetCode must be used exactly as specified here. The code
  53. *    _must_ be longword aligned.  Failure to duplicate the code EXACTLY
  54. *    may result in improper operation under certain system configurations.
  55. *
  56. *   RESULT
  57. *    This function never returns.
  58. *
  59. ****************************************************************************
  60.  
  61.         INCLUDE "exec/types.i"
  62.         INCLUDE "exec/libraries.i"
  63.  
  64.         XDEF    _ColdReboot
  65.         XREF    _LVOSupervisor
  66.  
  67. ABSEXECBASE        EQU 4        ;Pointer to the Exec library base
  68. MAGIC_ROMEND        EQU $01000000   ;End of Kickstart ROM
  69. MAGIC_SIZEOFFSET    EQU -$14        ;Offset from end of ROM to Kickstart size
  70. V36_EXEC        EQU 36        ;Exec with the ColdReboot() function
  71. TEMP_ColdReboot     EQU -726        ;Offset of the V36 ColdReboot function
  72.  
  73. _ColdReboot:    move.l    ABSEXECBASE,a6
  74.         cmp.w    #V36_EXEC,LIB_VERSION(a6)
  75.         blt.s    old_exec
  76.         jmp    TEMP_ColdReboot(a6)     ;Let Exec do it...
  77.         ;NOTE: Control flow never returns to here
  78.  
  79. ;---- manually reset the Amiga ---------------------------------------------
  80. old_exec:    lea.l    GoAway(pc),a5           ;address of code to execute
  81.         jsr    _LVOSupervisor(a6)      ;trap to code at (a5)...
  82.         ;NOTE: Control flow never returns to here
  83.  
  84. ;-------------- MagicResetCode ---------DO NOT CHANGE-----------------------
  85.         CNOP    0,4             ;IMPORTANT! Longword align!
  86. GoAway:     lea.l    MAGIC_ROMEND,a0      ;(end of ROM)
  87.         sub.l    MAGIC_SIZEOFFSET(a0),a0  ;(end of ROM)-(ROM size)=PC
  88.         move.l    4(a0),a0                 ;Get Initial Program Counter
  89.         subq.l    #2,a0             ;now points to second RESET
  90.         reset                 ;first RESET instruction
  91.         jmp    (a0)                     ;CPU Prefetch executes this
  92.         ;NOTE: the RESET and JMP instructions must share a longword!
  93. ;---------------------------------------DO NOT CHANGE-----------------------
  94.         END
  95.  
  96.